//
//  SightseeingReusableView.m
//  Lovelife
//
//  Created by dllo on 15/4/27.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "SightseeingReusableView.h"
#import "NightManager.h"
@implementation SightseeingReusableView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 创建背景图片
        self.imageView = [[UIImageView alloc]init];
        self.imageView.image = [UIImage imageNamed:@"Destination_Map@3x"];
        [self addSubview:self.imageView];
        [self.imageView release];
        
        // 创建个大洲图片名称数组
        NSArray *array1 = [NSArray arrayWithObjects:@"Destination_Asia",@"Destination_Europe",@"Destination_NA",@"Destination_SA",@"Destination_Oceania",@"Destination_Africa",@"Destination_Antarctica", nil];
        self.arr1 = array1;
        NSArray *array2 = [NSArray arrayWithObjects:@"Destination_Asia_Highlight",@"Destination_Europe_Highlight",@"Destination_NA_Highlight",@"Destination_SA_Highlight",@"Destination_Oceania_Highlight",@"Destination_Africa_Highlight",@"Destination_Antarctica_Highlight", nil];
        self.arr2 = array2;
        
        NSValue *value1 = [NSValue valueWithCGRect:CGRectMake(230, 20, 60, 60)];
        NSValue *value2 = [NSValue valueWithCGRect:CGRectMake(140, 15, 60, 60)];
        NSValue *value3 = [NSValue valueWithCGRect:CGRectMake(30, 25, 60, 60)];
        NSValue *value4 = [NSValue valueWithCGRect:CGRectMake(80, 88, 60, 60)];
        NSValue *value5 = [NSValue valueWithCGRect:CGRectMake(220, 90, 60, 60)];
        NSValue *value6 = [NSValue valueWithCGRect:CGRectMake(160, 80, 60, 60)];
        NSValue *value7 = [NSValue valueWithCGRect:CGRectMake(140, 130, 60, 60)];
        self.arrayOfRect = @[value1,value2,value3,value4,value5,value6,value7];
        for (int i = 0; i < 7; i++) {
            self.button = [BaseButton buttonWithType:UIButtonTypeCustom];
            self.button.tag = 100 + i;
//            self.button.frame =[self.arrayOfRect[i] CGRectValue];
            self.button.selected = NO;
            [self.button setBackgroundImage:[UIImage imageNamed:array1[i]] forState:UIControlStateNormal];
//            [self.button setBackgroundImage:[UIImage imageNamed:array2[i]] forState:UIControlStateHighlighted];
            [self.button addTarget:self action:@selector(changeAction:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.button];
        }
        self.nameLabele = [[BaseLabel alloc]init];
        [self addSubview:self.nameLabele];
        
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.imageView.frame = CGRectMake(0, 0, self.frame.size.width, 200);
    self.nameLabele.frame = CGRectMake(20, self.imageView.frame.size.height + 20, 200, 20);
    for (int a = 100; a < 107; a ++ ) {
        UIView *view = [self viewWithTag:a];
        BaseButton *button = (BaseButton *)view;
        button.frame = [self.arrayOfRect[a - 100] CGRectValue];
    }

}

- (void)changeAction:(BaseButton *)button
{
//    if (button.selected == YES) {
//        [button setBackgroundImage:[UIImage imageNamed:self.arr1[button.tag - 100]] forState:UIControlStateNormal];
//        NSLog(@"1");
//    }else{
    UIImage *im = [UIImage imageNamed:self.arr2[button.tag - 100]];
//    NSLog(@"%@")
        [button setBackgroundImage:im forState:UIControlStateHighlighted];
//        NSLog(@"2");

//    }
    button.selected = !button.selected;
    [self.delegate changeContinent:button.tag - 100];
}
- (void)setLightDayModel
{
    [NightManager setBackgroundColorWithView:self];
    [NightManager setLabelColorWithLabel:self.nameLabele];
    [NightManager setButtonTitleColorWithButton:self.button];

}
- (void)setNightDayModel
{
    [NightManager setBackgroundColorWithView:self];
    [NightManager setLabelColorWithLabel:self.nameLabele];
    [NightManager setButtonTitleColorWithButton:self.button];

}
- (void)dealloc
{
    [_imageView release];
    [_button release];
    [_arrayOfRect release];
    [_nameLabele release];
    [super dealloc];
}
@end
